/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bookshop.dao;

import com.bookshop.entity.Collection;
import com.bookshop.exception.EBookshopException;
import java.util.List;
import javax.ejb.Singleton;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Caroline
 */
@Singleton(mappedName = "com.bookshop.dao.collection")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class DaoCollectionImpl implements IDaoCollectionLocal, IDaoCollectionRemote {

    @PersistenceContext
    private EntityManager em;
    
    @Override
    public List<Collection> getCollectionByName(String collection) {
        try {
            return em.createNamedQuery("Collection.findByName").setParameter("name", "%"+collection+"%").getResultList();
        } catch(Throwable th) {
            throw new EBookshopException(th.getMessage(), th);
        }
    }   
}
